﻿Imports System.Text



Public Class GMapForm

    Private Sub GMapForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.GMapFormPos = Me.Location
        My.Settings.GMapFormSize = Me.Size

    End Sub

    Private Sub GMapForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FormPos(My.Settings.GMapFormPos)
        Me.Location = My.Settings.GMapFormPos
        Me.Size = My.Settings.GMapFormSize

    End Sub

    Public Function GMap(ByVal Street As String, ByVal ZIP As String, ByVal City As String)

        Try
            Dim queryAddress As New StringBuilder()
            queryAddress.Append("http://maps.google.ch/maps?q=")

            ' build street part of query string
            If Street <> String.Empty Then
                Street = Street.Replace(" ", "+")
                queryAddress.Append(Street + "," & "+")
            End If

            ' build zip code part of query string
            If ZIP <> String.Empty Then
                queryAddress.Append(ZIP + " ")
            End If

            ' build city part of query string
            If City <> String.Empty Then
                City = City.Replace(" ", "+")
                queryAddress.Append(City)
            End If

            ' pass the url with the query string to web browser control
            WebBrowser1.Navigate(queryAddress.ToString())
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString(), "Unable to Retrieve Map")
        End Try

        GMap = True

    End Function

End Class